package com.bdsy.business.controller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.bdsy.api.annotation.IgnoreAuth;
import com.bdsy.business.service.OrderService;
import com.bdsy.business.service.ShopSellInfoService;
import com.bdsy.business.service.ZlOrderService;
import com.bdsy.common.annotation.Json;
import com.bdsy.system.annotation.SysLog;

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class ZlShopManagerController {

	@Autowired
	ShopSellInfoService shopSellInfoService;
	
	@Autowired
	ZlOrderService zlOrderService;
	
	/**
	 * 租赁数量统计 
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "zlCountStatis")
	public Object zlCountStatis(String userId){
		Map<String,Object> map = new LinkedHashMap<>();
		//在售物品数量统计 
        int zlCount= shopSellInfoService.zlCount(userId);
        //已完成订单 
        int azlCount = zlOrderService.azlCount(userId);
        //未完成订单
        int nzlCount = zlOrderService.nzlCount(userId);
        //销量统计 暂时为空
		map.put("code", 200);
		map.put("msg", "success");
		map.put("zlCount", zlCount);
		map.put("azlCount", azlCount);
		map.put("nzlCount", nzlCount);
//		map.put("zlSalesCount", "99");
		return map;
	}
	
	/**
	 * 租赁销量统计 
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "zsaleStatis")
	public Object zsaleStatis(String userId){
		Map<String,Object> map = new LinkedHashMap<>();
		List name = new ArrayList<>();
		List count = new ArrayList<>();
		List<Map> zsaleStatis = zlOrderService.zsaleStatis(userId);
		for (int i = 0; i < zsaleStatis.size(); i++) {
			name.add(zsaleStatis.get(i).get("shop_type_name"));
			count.add(zsaleStatis.get(i).get("count"));
		}
		map.put("code", 200);
		map.put("msg", "success");
		map.put("name", name);
		map.put("count", count);
		return map;
	}
	
	/**
	 * 当前卖家用户租赁商品  已完成订单
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "areadyZlOrderList")
	public Object areadyZlOrderList(@RequestParam(value="userId",required=false)String userId,@RequestParam(value="shopTypeId",required=false)int shopTypeId,int lx,int qx){
		Map<String,Object> map = new LinkedHashMap<>();
		List<Map> areadyZlOrderList = zlOrderService.areadyZlOrderList(userId, shopTypeId, lx, qx);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("areadyZlOrderList", areadyZlOrderList);
		return map;
	}
	
	/**
	 * 当前卖家用户租赁商品  未完成订单 
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "nareadyZlOrderList")
	public Object nareadyZlOrderList(@RequestParam(value="userId",required=false)String userId,@RequestParam(value="shopTypeId",required=false)int shopTypeId,int zlStatus,int status,int qx){
		Map<String,Object> map = new LinkedHashMap<>();
		List<Map> nareadyZlOrderList = zlOrderService.nareadyZlOrderList(userId, shopTypeId,zlStatus,status, qx);
		map.put("nareadyOrderList", nareadyZlOrderList);
		return map;
	}
} 
